package sword.T21;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-28 0:13:35 星期一
 */

class Solution {
    public int[] exchange(int[] nums) {
        int left = 0, right = nums.length-1;
        while (left < right) {
            while (left < right && nums[left] % 2 == 1)
                left++;
            while (left < right && nums[right] % 2 == 0)
                right--;
            if (left < right)
                swap(nums, left, right);
        }
        return nums;
    }

    private void swap(int[] nums, int a, int b) {
        int temp = nums[a];
        nums[a] = nums[b];
        nums[b] = temp;
    }
}